using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;

namespace Phoenix.Xna.Framework.ContentPipeline.Animation
{
    public class AnimationClipContent
    {
        public string Name { get; private set; }
        public TimeSpan Duration { get; private set; }
        public AnimationChannelContentDictionary Channels { get; private set; }

        internal AnimationClipContent(string name, AnimationChannelContentDictionary channels, TimeSpan duration)
        {
            Name = name;
            Channels = channels;
            Duration = duration;
        }

        internal void Write(ContentWriter output)
        {
            output.Write(Name);
            output.WriteObject<TimeSpan>(Duration);
            output.Write(Channels.Count);

            foreach (KeyValuePair<string, AnimationChannelContent> pair in Channels)
            {
                output.Write(pair.Key);
                AnimationChannelContent animationChannel = pair.Value;
                output.Write(animationChannel.Count);

                foreach (AnimationKeyframeContent keyframe in animationChannel)
                {
                    output.WriteObject<TimeSpan>(keyframe.Time);
                    output.Write(keyframe.Pose.Translation);
                    output.Write(keyframe.Pose.Orientation);
                    output.Write(keyframe.Pose.Scale);
                }
            }
        }
    }
}